package org.example.hansp.collection_.collections_;



import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@SuppressWarnings({"all"})
public class Collections_ {
    public static void main(String[] args) {
        List list = new ArrayList();
        list.add("Alisa");
        list.add("Alisa");
        list.add("Lim");
        list.add("Cral");
        list.add("David");
        //自然排序
        Collections.sort(list);
        System.out.println(list);
//反转
        Collections.reverse(list);
        System.out.println(list);
//随机排序
        for (int i = 0; i < 3; i++) {
            Collections.shuffle(list);
            System.out.println(list);
        }
        //指定排序
        Collections.sort(list,new Comparator<String>() {
            public int compare(String o1, String o2) {
                return o1.length() - o2.length();
            }
        });
        System.out.println(list);
//将指定list集合中i处元素与j处元素互换
        Collections.swap(list, 0, 1);
        System.out.println(list);
        //根据自然排序返回元素的最大值
        System.out.println(Collections.max(list));
        //根据指定返回最大值
        System.out.println(Collections.max(list,new Comparator<String>() {
            public int compare(String o1, String o2) {
                return o1.length() - o2.length();
            }
        }));
        //最小值
        System.out.println(Collections.min(list));
        System.out.println(Collections.min(list,new Comparator<String>() {
            public int compare(String o1, String o2) {
                return o1.length() - o2.length();
            }
        }));
//返回指定集合中指定元素的个数
        int alisa = Collections.frequency(list, "Alisa");
        System.out.println(alisa);
        //拷贝
        ArrayList desc= new ArrayList();
        for (int i = 0; i < list.size(); i++) {
            desc.add("");
        }
        Collections.copy(desc,list);
        System.out.println(desc);

        //替换
        Collections.replaceAll(desc,"Cral","卡尔");
        System.out.println(desc);
    }

}
